﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="TSV.Areas.Administration.Models" %>
<script type="text/javascript" src="/Scripts/highslide/highslide.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/highslide/highslide.css" />
<script src="/Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
<%
    PromotionDao proDao = new PromotionDao();
    Promotion promotion = (Promotion)ViewData.Model;    
%>
<script type="text/javascript">
    hs.graphicsDir = '/Scripts/highslide/graphics/';
    hs.outlineType = 'rounded-white';

    $(document).ready(function () {
        CKEDITOR.replace('PromotionInfo', {
            filebrowserImageUploadUrl: '/Administration/Common/UploadImage',
            filebrowserFlashUploadUrl: '/Administration/Common/UploadFlash',
            entities: false
        });
        $("#PromotionForm").validate({
            debug: false,
            errorElement: "span",
            errorPlacement: function (error, element) {
                error.tooltip({
                    bodyHandler: function () {
                        return error.html();
                    }
                });
                error.insertAfter(element);
            },
            rules: {
                Title: {
                    required: true
                }
            }
        });
        $("#btnChangePhoto").click(function () {
            var url = "/Administration/Common/UploadImage?controller=<%=Constants.PROMOTION_DEFAULT_VALUE %>&recordID=" + $('#PromotionID').val() + "&saveTo=<%=Constants.PHOTO_PATH_ROOT_PARTNER %>&width=290&height=92";
            JS_LIB.popUpWindow(url, '#Photograph', 'Upload Hình');
            return false;
        });
    });
</script>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="edit">
    <tr>
        <td class="label">
            Hình Ảnh
        </td>
        <td class="input">
            <table>
                <tr>
                    <td>
                        <%
                            string labelPhoto = "<img src='/Content/Images/Common/nopic.gif' height='92px' width='290px' />";
                            if (ViewData.Model == null)
                            {
                                Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(promotion.Image) || (!string.IsNullOrEmpty(promotion.Image) && promotion.Image == Constants.NO_IMAGE))
                                {
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                                else
                                {
                                    labelPhoto = "<a id='thumb1' href='" + Constants.PHOTO_PATH_ROOT_PARTNER + promotion.Image
                                                    + "' class='highslide' onclick='return hs.expand(this)'>"
                                                    + "<img id='imgPhoto' src='" + Constants.PHOTO_PATH_ROOT_PARTNER + promotion.Image
                                                    + "' alt='Highslide JS' title='Nhấp vào để phóng to' height='92px' width='290px' /></a>";
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                            }
                            if (ViewData.Model == null)
                            {
                                Response.Write(Html.Hidden("PromotionID", ""));                           
                                Response.Write(Html.Hidden("Photograph", ""));
                                Response.Write(Html.Hidden("PartnerID", ViewData["PartnerID"]));
                                Response.Write(Html.Hidden("LastOrder", ViewData["LastOrder"]));
                            }
                            else
                            {
                                Response.Write(Html.Hidden("PromotionID", promotion.ID));
                                Response.Write(Html.Hidden("ID", promotion.ID));//for removeImage
                                Response.Write(Html.Hidden("Photograph", promotion.Image));
                                Response.Write(Html.Hidden("PartnerID", promotion.PartnerID));
                            }                            
                        %>
                    </td>
                    <td valign="top">
                        <input type="button" class="upload_image" id="btnChangePhoto" value="" title="Đổi hình" />
                        <%  string stylePhoto = "display: none";
                            if (ViewData.Model != null)
                            {
                                if (!string.IsNullOrEmpty(promotion.Image) && promotion.Image != Constants.NO_IMAGE)
                                {
                                    stylePhoto = "display: block";
                                }
                            }
                        %>
                        <input type="button" id="btnRemoveImage" class="remove_image" style="<%=stylePhoto %>"
                            onclick="JS_LIB.msgConfirmBox('Bạn có chắc là bạn muốn xóa hình ảnh?', 450,'JS_LIB.removeImageWithSize(\'<%=Constants.PROMOTION_DEFAULT_VALUE %>\',290,92)','Xóa Hình');"
                            value="" title="Xóa Hình" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="label required" style="vertical-align: top">
            Tiêu Đề <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Title", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Title", promotion.Title, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>        
    <tr>
        <td class="label" style="vertical-align: top">
            Tin Khuyến Mãi
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextArea("PromotionInfo", string.Empty, new {@style = "width:600px;height:200px" }));
                }
                else
                {
                    Response.Write(Html.TextArea("PromotionInfo", CommonFunc.SetHtmlForCKEditor(promotion.PromotionInfo), new {@style = "width:600px;height:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label" style="vertical-align: top">
            Kích hoạt
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.CheckBox("Active"));
                }
                else
                {
                    Response.Write(Html.CheckBox("Active", promotion.Active));
                }                
            %>
        </td>
    </tr>
    <tr>        
        <td colspan="2" align="center">
            <input type="submit" class="save" value="" alt="" />
            <input type="button" class="cancel" value="" alt="" onclick="JS_LIB.back()" />
        </td>
    </tr>
</table>

